import QtQuick 2.0
import QtQml.Models 2.1

ListModel {
    id: mainformModel

    ListElement {
        name: "DataBar"
        sourcePath: "DataBarContainer.qml"
        visible: true
    }
    ListElement {
        name: "DataChart"
        sourcePath: "DataChart.qml"
        visible: true
    }
    ListElement {
        name: "ValueForm"
        sourcePath: "ValueForm.qml"
        visible: true
    }

//    ===============================================

    function getIconPath(section) {
        var ggpicon="menu/menu_button_location_setting.png"
        for (var i = 0; i < count; ++i) {
            var obj = get(i)
            if (obj["group"] === section) {
                if(obj["groupIcon"] === undefined){
                    return ggpicon
                }else{
                ggpicon = obj["groupIcon"]
                    return obj["groupIcon"]
                }
            }
        }
    }

    function updateSection(section, isOpen) {
        for (var i = 0; i < count; ++i) {
            var obj = get(i)
            if (obj["group"] === section) {
                setProperty(i, "groupOpen", isOpen)
            }
        }
    }
    function search(text) {
        var i = 0
        if (text.length <= 0) {
            for ( i = 0; i < count; ++i) {
                setProperty(i, "visible", true)
            }
        } else {
            var lowerText = String(text).toLowerCase()
            for (i = 0; i < count; ++i) {
                var obj = get(i)
                if (qsTr(obj["name"]).toLowerCase().indexOf(lowerText) >= 0) {
                    setProperty(i, "visible", true)                    
                    setProperty(i, "groupOpen", true)
                } else {
                    setProperty(i, "visible", false)
                }
            }
        }
    }
}
